package com.seeTools.boot.pc.controller.sys;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seeTools.boot.api.entity.sys.SysOperLog;
import com.seeTools.boot.common.annotation.Log;
import com.seeTools.boot.common.core.PageQuery;
import com.seeTools.boot.common.core.Result;
import com.seeTools.boot.common.enums.BusinessType;
import com.seeTools.boot.pc.service.sys.SysOperLogService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author seeTools
 * @since 2024-05-12
 */
@Validated
@RestController
@RequestMapping("/sys/oper/log")
public class SysOperLogController {

    @Resource
    private SysOperLogService sysOperLogService;

    /**
     * 分页查询
     *
     * @param pageQuery
     * @return
     */
    @PostMapping("/list")
    public Result<Page<SysOperLog>> findList(@RequestBody PageQuery<SysOperLog> pageQuery) {
        Page<SysOperLog> pageInfo = sysOperLogService.findList(pageQuery);
        return Result.success(pageInfo);

    }

    /**
     * 修改
     *
     * @return
     */
    @SaCheckPermission("oper.edit")
    @Log(title = "操作日志数据", businessType = BusinessType.UPDATE)
    @PutMapping()
    public Result<Void> edit(@RequestBody SysOperLog sysOperLog) {
        return Result.state(sysOperLogService.updateOnLock(sysOperLog));
    }

    /**
     * 删除
     *
     * @return
     */
    @SaCheckPermission("oper.del")
    @Log(title = "操作日志数据", businessType = BusinessType.DELETE)
    @DeleteMapping()
    public Result<Void> remove(@RequestBody SysOperLog sysOperLog) {
        sysOperLogService.clean(sysOperLog);
        return Result.success();
    }


    /**
     * 获取全部
     *
     * @return
     */
    @DeleteMapping("/all")
    public Result<Void> removeAll() {
        sysOperLogService.cleanAll();
        return Result.success();
    }


    /**
     * 添加
     *
     * @return
     */
    @SaCheckPermission("oper.add")
    @Log(title = "操作日志数据", businessType = BusinessType.INSERT)
    @PostMapping()
    public Result<Void> add(@RequestBody SysOperLog sysOperLog) {
        return Result.state(sysOperLogService.save(sysOperLog));
    }

    /**
     * 导出
     *
     * @param response
     * @param sysOperLog
     */
    @SaCheckPermission("oper.export")
    @Log(title = "操作日志数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody SysOperLog sysOperLog) {
        List<SysOperLog> list = sysOperLogService.selectDataList(sysOperLog);
    }
}
